package com.qst.yunpan.service.impl;

import com.qst.yunpan.dao.UserDao;
import com.qst.yunpan.pojo.User;
import com.qst.yunpan.service.UserService;
import com.qst.yunpan.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    public User findUser(User user) {
        try {
            // 设置密码为MD5加密后的密码
            user.setPassword(UserUtils.MD5(user.getPassword()));
            User existUser = userDao.findUser(user);
            return existUser;
        } catch (Exception e) {
            return null;
        }
    }

    public String getCountSize(String username) {
        String countSize = null;
        try {
            countSize = userDao.getCountSize(username);
        } catch (Exception e) {
            e.printStackTrace();
            return countSize;
        }
        return countSize;
    }

    @Override
    public boolean addUser(User user) {
        User isuser = userDao.checkUser(user);
        if (isuser == null) {
            user.setPassword(UserUtils.MD5(user.getPassword()));
            userDao.addUser(user);
        } else return false;
        return true;
    }
}
